package com.wanxi.dao.impl;

import com.wanxi.dao.CuisineDao;
import com.wanxi.dto.CuisineDto;
import com.wanxi.model.CuisineModel;
import com.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CuisineDaoImpl implements CuisineDao {
    public int add(CuisineModel model) {
        return 0;
    }

    public int update(CuisineModel model) {
        return 0;
    }

    public int delete(CuisineModel model) {
        return 0;
    }

    public CuisineDto findById(CuisineModel model) {
        return null;
    }

    public List<CuisineDto> findAll(CuisineModel model) {
        String sql = "select * from cuisine where enable=" + model.getEnable();
        ResultSet query = JDBC.query(sql);
        List<CuisineDto> list = new ArrayList<>();
        try {
            while (query.next()) {
                list.add(CuisineDto.builder()
                        .id(query.getInt("id"))
                        .name(query.getString("name"))
                        .createTime(query.getString("create_time"))
                        .build());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }

    public int count(CuisineModel model) {
        String sql="select count(*) count from cuisine where enable="+model.getEnable();
        return JDBC.count(sql);
    }
}
